import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:mtf/R.dart';
import 'package:mtf/app/modules/withdrawal_module/withdrawal_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
import 'package:mtf/app/widget/SettingBar.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class withdrawalPage extends GetView<withdrawalController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(title: "提款"),
      body: Container(
        margin: EdgeInsets.all(10),
        child: ListView.builder(
          shrinkWrap: true,
          itemBuilder: (context, index) {
            if (index == 0) {
              return Obx(() {
                return SettingBar(
                    onTap: () {
                      controller.bankList();
                    },
                    radio: 10,
                    leftIcon: SvgPicture.asset(R.assetsImgIvSvgCard),
                    leftText: controller.bankNameObs.value,
                    rightIcon: SvgPicture.asset(
                      R.assetsImgIcSvgRight,
                      color: c_999999,
                    ));
              });
            } else if (index == 1) {
              return Container(
                margin: EdgeInsets.symmetric(vertical: 10),
                padding: EdgeInsets.all(10),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10)),
                child: Column(
                  children: [
                    Flex(
                      direction: Axis.horizontal,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          "提款金额",
                          style: TextStyle(color: c_333333, fontSize: 15),
                        ),
                        Text(
                          "手续费0.0%",
                          style: TextStyle(color: c_999999, fontSize: 13),
                        ),
                      ],
                    ),
                    Container(
                      width: double.infinity,
                      child: TextField(
                        controller: controller.amountController,
                        keyboardType: TextInputType.numberWithOptions(
                            decimal: true),
                        inputFormatters: [
                          FilteringTextInputFormatter.allow(RegExp("[0-9.]"))
                        ],
                          onChanged: (value) {
                            if (value.contains(".")) {
                              var vv = value.split('.');
                              if (vv.length > 2) {
                                controller.amountController.text = '${vv[0]}.${vv[1]}';
                              }
                              controller.amountController.selection =
                                  TextSelection.fromPosition(TextPosition(
                                      offset: controller.amountController.text
                                          .length));
                            }
                          },
                        decoration: InputDecoration(
                            hintText: "请输入提款金额",
                            hintStyle: TextStyle(color: c_bbbbbb, fontSize: 18),
                            suffixIcon: Container(
                              width: 40,
                              child: Text("USD"),
                              alignment: Alignment.center,
                            ),
                            enabledBorder: UnderlineInputBorder(
                                borderSide:
                                BorderSide(color: c_bbbbbb, width: 1.0))),
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Obx(() {
                            return Text.rich(TextSpan(children: [
                              TextSpan(
                                  text: "可提款余额",
                                  style:
                                  TextStyle(color: c_999999, fontSize: 12)),
                              TextSpan(
                                  text: " ${controller.mt5BalanceObs.value}USD",
                                  style: TextStyle(
                                      color: c_f12f38,
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold))
                            ]));
                          }),
                          InkWell(
                            onTap: () {
                              controller.withdrawAll();
                            },
                            child: Text(
                              "全部使用",
                              style: TextStyle(
                                  color: c_326BF9, fontWeight: FontWeight.bold),
                            ),
                          )
                        ],
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.symmetric(vertical: 10),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "到账金额",
                            style: TextStyle(
                                color: c_333333,
                                fontSize: 15,
                                fontWeight: FontWeight.w500),
                          ),
                          Obx(() {
                            return Text(
                              "￥${controller.preAccount.value}",
                              style: TextStyle(
                                  color: c_333333,
                                  fontSize: 15,
                                  fontWeight: FontWeight.w500),
                            );
                          })
                        ],
                      ),
                    )
                    // SettingBar(
                    //   leftIcon: Text(
                    //     "可提款余额",
                    //     style: TextStyle(color: c_999999, fontSize: 12,height: 1.1),
                    //   ),
                    //   leftText: "5542256",
                    //   leftTextSize: 12,
                    // )
                  ],
                ),
              );
            } else {
              return Container(
                margin: const EdgeInsets.only(top: 30, left: 10, right: 10),
                width: double.maxFinite,
                height: 48,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(24),
                  color: c_f12f38,
                ),
                child: TextButton(
                    child: Text("提交",
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.bold)),
                    onPressed: () {
                      controller.clickSub();
                    }),
              );
            }
          },
          itemCount: 3,
        ),
      ),
    );
  }


}
